package com.fq.myapplication.fragment;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.fq.myapplication.R;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.fq.myapplication.R;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

public class ShareDialogFragment extends BottomSheetDialogFragment {
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        // 绑定复制链接布局
        LinearLayout copyLinkLayout = view.findViewById(R.id.share_copy_link);

        String linkToCopy = "https://www.example.com";

        copyLinkLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("ShareFragment", "复制链接被点击");
                copyLinkToClipboard(linkToCopy);
                Toast.makeText(getContext(), "链接已复制", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void copyLinkToClipboard(String link) {
        // 获取剪贴板服务
        ClipboardManager clipboard = (ClipboardManager) requireContext().getSystemService(Context.CLIPBOARD_SERVICE);
        // 创建ClipData对象，包含要复制的文本
        ClipData clip = ClipData.newPlainText("label", link);
        // 将ClipData对象设置到剪贴板
        clipboard.setPrimaryClip(clip);
    }
}
